home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / nos042_s / st.c < prev    next >
C/C++ Source or Header  |  1994-09-16  |  24KB  |  803 lines

  1. /****************************************************************************
  2. *                                                                           *
  3. *    st.c - System routines for Atari by David Nash (dnash@chaos.demon.co.uk) *
  4. *                                                                           *
  5. *  This version includes code provided by:-                                 *
  6. *      Walter Doerr, DG2KK (dg2kk@cup.portal.com) and Rob Janssen PE1CHL     *
  7. *                                                                           *
  8. *    00.01.93 DFN - Initial version                                                         *
  9. *  28.08.94 DFN - Cleanup, redundent functions deleted.                             *
  10. *                        rflush, ptol & ltop now defined as macros in global.h         *
  11. *                                                                           *
  12. ****************************************************************************/
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <dos.h>        
  17. #include <ext.h>
  18. #include <osbind.h>
  19. #include <sys/types.h>
  20. #include <sys/stat.h>
  21. #include <sys/except.h>
  22.  
  23. #ifdef OVERSCAN
  24. #include <overscan.h>
  25. #endif
  26.  
  27. #include "global.h"
  28. #include "session.h"
  29. #include "config.h"
  30. #include "mbuf.h"
  31. #include "internet.h"
  32. #include "iface.h"
  33. #include "st.h"
  34. #include "st_asy.h"
  35. #include "cmdparse.h"
  36. #include "asy.h"
  37. #include "socket.h"
  38.  
  39. /*
  40.     increase default stacksize
  41. */
  42.  
  43. unsigned long _STACK = 16536;
  44.  
  45. /* Interface list header */
  46.  
  47. struct iface *ifaces;
  48.  
  49. static    int32        clksec(void);
  50. static   int32     iss(void);
  51. volatile int         Tick = 0;                    /* updated by timer interrupt    */
  52. volatile int32        Clock = 0;                    /* updated by timer interrupt */
  53. void        (*etv_timer)();
  54. void     st_tick(void);
  55. static   int Virtual_Interrupt_Enable = 0;
  56.  
  57. extern int Escape;                    /* Escape character - enter command mode    */
  58. extern struct proc *Display;
  59.  
  60. /* Prototypes for functions defined in st.c */
  61.  
  62. void     ioinit(void);
  63. void     iostop(void);
  64. void     __saveds sys_tick(void);
  65. void     restore_vec(void);
  66. int32 secclock(void);
  67. int32 msclock(void);
  68. int     kbread(void);
  69. int     istate(void);
  70. int     dirps(void);
  71. void     restore(int foo);
  72. int     disable(void);
  73. void  dispscreen(int flag);
  74. void  outscreen(int flag);
  75. void     doshell(int argc, char **argv);
  76. void     memstat(void);
  77. void     iosize(int i);
  78. void     sysreset(void);
  79. void     set_stdout(int mode);
  80. #if 0
  81. long     ptol(void *ptr);
  82. void     *ltop(long l);
  83. void     rflush(void);
  84. #endif
  85. void     display(int i, void *v1, void *v2);
  86. void     *mallocw(unsigned int n);
  87. void     *callocw(unsigned int n, unsigned int size);
  88. unsigned long availmem(void);
  89.  
  90.  
  91. /*---------------------------------------------------------------------------
  92.     define function keys
  93. ---------------------------------------------------------------------------*/
  94.  
  95. struct funcstr {
  96.     char fkey;
  97.     char alloced;
  98.     char *fvalue;
  99.     int  special;
  100. };
  101.  
  102. static far struct funcstr fkeys[] = {
  103.     { 15,0,NULLCHAR, 0 },        /* tab + shift     */
  104.     { 59,1,NULLCHAR, 0 },          /* F1                 */
  105.     { 60,1,NULLCHAR, 0 },          /* F2                 */
  106.     { 61,1,NULLCHAR, 0 },          /* F3                 */
  107.     { 62,1,NULLCHAR, 0 },          /* F4                 */
  108.     { 63,0,NULLCHAR, 0 },        /* F5                 */
  109.     { 64,0,NULLCHAR, 0 },        /* F6                 */
  110.     { 65,0,NULLCHAR, 0 },        /* F7                 */
  111.     { 66,0,NULLCHAR, 0 },        /* F8                 */
  112.     { 67,0,NULLCHAR, 0 },        /* F9                 */
  113.     { 68,0,NULLCHAR, 0 },        /* F10                 */
  114.     { 71,1,NULLCHAR, 0 },        /* home                */
  115.     { 72,1,NULLCHAR, 0 },        /* up arrow            */
  116.     { 73,1,NULLCHAR, 0 },        /* pgup                 */
  117.     { 75,1,NULLCHAR, 0 },        /* left arrow         */
  118.     { 77,1,NULLCHAR, 0 },        /* right arrow     */
  119.     { 79,1,NULLCHAR, 0 },        /* end                 */
  120.     { 80,1,NULLCHAR, 0 },        /* down arrow         */
  121.     { 81,1,NULLCHAR, 0 },        /* pgdn                 */
  122.     { 82,1,NULLCHAR, 0 },        /* ins                 */
  123.     { 83,1,NULLCHAR, 0 },        /* del                 */
  124.     { 84,0,NULLCHAR, 0 },        /* F1 + shift        */
  125.     { 85,0,NULLCHAR, 0 },        /* F2 + shift        */
  126.     { 86,0,NULLCHAR, 0 },        /* F3 + shift        */
  127.     { 87,0,NULLCHAR, 0 },        /* F4 + shift        */
  128.     { 88,0,NULLCHAR, 0 },        /* F5 + shift        */
  129.     { 89,0,NULLCHAR, 0 },        /* F6 + shift        */
  130.     { 90,0,NULLCHAR, 0 },        /* F7 + shift        */
  131.     { 91,0,NULLCHAR, 0 },        /* F8 + shift        */
  132.     { 92,0,NULLCHAR, 0 },        /* F9 + shift        */
  133.     { 93,0,NULLCHAR, 0 },        /* F10 + shift        */
  134.     { 94,0,NULLCHAR, 0 },        /* F1 + control    */
  135.     { 95,0,NULLCHAR, 0 },        /* F2 + control    */
  136.     { 96,0,NULLCHAR, 0 },        /* F3 + control    */
  137.     { 97,0,NULLCHAR, 0 },        /* F4 + control    */
  138.     { 98,0,NULLCHAR, 0 },        /* F5 + control    */
  139.     { 99,0,NULLCHAR, 0 },        /* F6 + control    */
  140.     { 100,0,NULLCHAR, 0 },        /* F7 + control    */
  141.     { 101,0,NULLCHAR, 0 },        /* F8 + control    */
  142.     { 102,0,NULLCHAR, 0 },        /* F9 + control    */
  143.     { 103,0,NULLCHAR, 0 },        /* F10 + control    */
  144.     { 104,0,NULLCHAR, 0 },        /* F1 + alt            */
  145.     { 105,0,NULLCHAR, 0 },        /* F2 + alt            */
  146.     { 106,0,NULLCHAR, 0 },        /* F3 + alt            */
  147.     { 107,0,NULLCHAR, 0 },        /* F4 + alt            */
  148.     { 108,0,NULLCHAR, 0 },        /* F5 + alt            */
  149.     { 109,0,NULLCHAR, 0 },        /* F6 + alt            */
  150.     { 110,0,NULLCHAR, 0 },        /* F7 + alt            */
  151.     { 111,0,NULLCHAR, 0 },        /* F8 + alt            */
  152.     { 112,0,NULLCHAR, 0 },        /* F9 + alt            */
  153.     { 113,0,NULLCHAR, 0 },        /* F10 + alt        */
  154.     { 114,0,NULLCHAR, 0 },        /* PrtSc + ctl        */
  155.     { 117,0,NULLCHAR, 0 },        /* end    + ctl     */
  156.     { 118,0,NULLCHAR, 0 },        /* pgup + ctl         */
  157.     { 119,0,NULLCHAR, 0 },        /* home + ctl         */
  158.     { 132,0,NULLCHAR, 0 },        /* pgdn + ctl         */
  159.     {   0,0,NULLCHAR,0 }
  160. };
  161.  
  162. char Leftover = 0;
  163. char *Nextkey;
  164.  
  165. /* #ifdef SCREEN */
  166.  
  167. void *newscr, *newscradr;    /* 32k memory allocated to 2nd video screen */
  168. void *old_logscr, *old_physcr;
  169. void *new_logscr, *new_physcr;
  170.  
  171. int toggle = 0;            /* toggle between normal and trace screen */
  172. int printtrace = 0;        /* send trace to printer (controlled by F2) */
  173. /*  #endif */
  174.  
  175. char  *shell,*getenv();        /* Name of command shell for exec                 */
  176. int    rows=25;                    /* Number of text rows on screen (may be 50) */
  177. FILE    *Rawterm = stdout;    /* console for ttydriv etc                            */
  178.  
  179.  
  180. /*---------------------------------------------------------------------------
  181.     ioinit - This routine handles the machine specific setup tasks
  182. ---------------------------------------------------------------------------*/
  183.  
  184. void ioinit()
  185. {
  186. #ifdef OVERSCAN    
  187. unsigned long ptr;
  188. #endif
  189.  
  190. #define lmalloc(s) malloc(s) 
  191.  
  192. #ifdef SCREEN
  193. #ifdef OVERSCAN
  194.     if (__sxv(4200) != 4200) {            /* Is OverScan active            */
  195.         OSCAN_SCREEN    *oscan_scr;
  196.         oscan_scr = (OSCAN_SCREEN *)__pxs(4201, -1);        /* xbios 4201        */
  197.         newscradr = malloc((oscan_scr->length_of_screen) + 256);
  198.  
  199.         if (newscradr == NULL)    {
  200.             printf("st.c/ioinit: malloc failed \n");
  201.             exit(-1);
  202.         }
  203.         ptr = (unsigned long)newscradr;
  204.         new_logscr = (void *)(((ptr+256)&0xffffff00L)+ oscan_scr->logbase_offset);
  205.         new_physcr = (void *)(((ptr+256)&0xffffff00L)+ oscan_scr->physbase_offset);
  206.     } 
  207.     else {
  208.         newscradr = malloc(32*1024L);
  209.         ptr = (unsigned long)newscradr;
  210.         new_physcr = (void *)((ptr+255) & 0xffffff00L);    /* 256 byte boundary */
  211.         new_logscr = new_physcr;
  212.     }  
  213. #else
  214.     newscradr = lmalloc(32*1024L);    /* allocate 32k for 2nd video screen */     
  215.     ptr = (unsigned long)newscradr;
  216.     new_physcr = (void *)((ptr+255) & 0xffffff00L);    /* 256 byte boundary */
  217.     new_logscr = new_physcr;
  218. #endif   /* OVERSCAN */
  219.  
  220.     old_physcr = Physbase();                    /* remember displayed screen address */
  221.     old_logscr = Logbase();                        /* remember output screen address */
  222.     Cconws("\033j");                                /* Save cursor position */
  223.  
  224.     (void) Vsync();                                /* wait for vsync */
  225.     (void) Setscreen(new_logscr, new_physcr, -1);    /* switch to 2nd screen */
  226.  
  227.     Cconws("\033H\033J");                        /* cursor home, clear screen */
  228.     Cconws("\033k");                                /* restore cursor position */
  229.  
  230.     (void) Vsync();                                /* wait for vsync                        */
  231.     (void) Setscreen(old_logscr, old_physcr , -1);    /* restore old screen */
  232. #endif
  233.  
  234.     Cconws("\033v\033e\n");        /* Autowrap on, Cursor on */
  235.     (void) Cursconf(2,0);        /* make the cursor blink (3=steady) */
  236.  
  237.  
  238.     shell = getenv("NROWS");
  239.     if (shell != NULL)
  240.         rows = atoi(shell);
  241.  
  242.     shell = getenv("SHELL");
  243.     if (shell == NULL)
  244.         shell="\\bin\\gulam.prg";
  245.  
  246.     etv_timer = Setexc(0x100, st_tick);          /* re-vector etv_timer to st_tick    */
  247. }
  248.  
  249.     
  250. /*---------------------------------------------------------------------------
  251.     iostop - Called just before exiting. 
  252. ---------------------------------------------------------------------------*/
  253.  
  254. void iostop(void)
  255. {
  256.     struct iface *ifp, *iftmp;
  257.  
  258.     for (ifp = Ifaces; ifp != NULLIF; ifp = iftmp) {
  259.         iftmp = ifp->next;
  260.         if_detach(ifp);                            /* issue detatch for active i/f    */
  261.     }
  262.  
  263.     (void)Setexc(0x100, etv_timer);             /* restore etv_timer vector        */
  264.     
  265. #ifdef SCREEN
  266.     dispscreen(0);                                    /* switch back to original screen*/
  267.     toggle = 0;
  268.     free(newscradr);
  269. #endif
  270.  
  271. }
  272.  
  273. /****************************************************************************
  274. *                                                                           *
  275. *    System Timer functions                                                                     *
  276. *                                                                           *
  277. ****************************************************************************/
  278.  
  279. /*---------------------------------------------------------------------------
  280.     mfp_tick - process ticks from MFP Timer A - called by etv_timer interrupt
  281. ---------------------------------------------------------------------------*/
  282.  
  283. void __saveds sys_tick(void)
  284. {    
  285.     Tick++;
  286.     Clock++;
  287.     if (Virtual_Interrupt_Enable)
  288.           psignal((void *)&Tick, 1); 
  289. }
  290.  
  291.  
  292. /*---------------------------------------------------------------------------
  293.     secclock - returns number of seconds since startup 
  294. ---------------------------------------------------------------------------*/
  295.  
  296. int32 secclock(void)
  297. {
  298.     return Clock / TICKSEC;
  299. }
  300.  
  301.  
  302. /*---------------------------------------------------------------------------
  303.     msclock - return number of milli-seconds since startup
  304. ---------------------------------------------------------------------------*/
  305.  
  306. int32 msclock(void)
  307. {
  308.     return Clock * MSTICK;
  309. }
  310.  
  311.  
  312. /****************************************************************************
  313. *                                                                           *
  314. *    System keyboard functions                                                                 *
  315. *                                                                           *
  316. ****************************************************************************/
  317.  
  318. /*---------------------------------------------------------------------------
  319.     kbread - get a key press.  GEMDOS functions used to provide type-ahead
  320. ---------------------------------------------------------------------------*/
  321.  
  322. int kbread()
  323. {
  324.     int     c, i, j;
  325.     long    raw;
  326.  
  327.     if ((c = Leftover) != 0)  {
  328.         Leftover = *Nextkey++;                    /* get next character from str    */
  329.         return c;                                    /* return char from FN key str    */
  330.     }
  331.  
  332.     while (Cconis() == 0) 
  333.         pwait(NULL);                                /* no key waiting, release CPU    */
  334.     
  335.     raw = Crawcin();                                /* get ASCII & scan code from        */
  336.     c = raw & 0x7f;                                /* remove scan codes                 */
  337.  
  338.     if (c != 0)
  339.         return c;                                    /* return normal character            */
  340.  
  341.     /* process function keys                                                                 */
  342.  
  343.     c = (raw >> 16) & 0xff;                        /* get key code                        */
  344.     
  345.     if (c == Escape)                                /* escape character ?                */
  346.         return -2;                                    /* switch to command line            */
  347.  
  348.     for (i=0; (j = fkeys[i].fkey) != 0; i++)
  349.         if (j == c) {                                /* look for function key code        */    
  350.             Nextkey = fkeys[i].fvalue;            /* point to FN key string            */
  351.  
  352.             if (fkeys[i].special == 1)    {        /* special key ?                        */
  353.                 Leftover = *Nextkey++;            /* point to next char in string  */
  354.                 return -2;                            /* switch to command line            */
  355.             }
  356.  
  357.             if (Nextkey == NULLCHAR) {            
  358.             /*    c = -1;         */                /* no more characters                */
  359.                 return c + 255; 
  360.             }
  361.  
  362.             if ((c = *Nextkey++) != 0)
  363.                 Leftover = *Nextkey++;            /* get netx character                */
  364.             else
  365.                 c = -1;                                /* no more characters                */
  366.             return c;                                /* return character                    */
  367.         }
  368. }
  369.  
  370. /*---------------------------------------------------------------------------
  371.     dofkey - setup function key strings
  372. ---------------------------------------------------------------------------*/
  373.  
  374. int dofkey(int argc, char*argv[], void *p)
  375. {
  376.     int c,i,j;
  377.     char *q, *r, *special;
  378.     char str[100];
  379.  
  380.     if (argc == 1) {
  381.        tprintf("key num    key  num    key  num    key  num   key   num\n");
  382.        tprintf("f1   59    sf1   84    cf1   94    af1  104   undo   97\n");
  383.        tprintf("f2   60    sf2   85    cf2   95    af2  105   help   98\n");
  384.        tprintf("f3   61    sf3   86    cf3   96    af3  106   home   71\n");
  385.        tprintf("f4   62    sf4   87    cf4   97    af4  107            \n");
  386.        tprintf("f5   63    sf5   88    cf5   98    af5  108   arup   72\n");
  387.        tprintf("f6   64    sf6   89    cf6   99    af6  109   ardn   80\n");
  388.        tprintf("f7   65    sf7   90    cf7  100    af7  110   ar l   75\n");
  389.        tprintf("f8   66    sf8   91    cf8  101    af8  111   ar r   77\n");
  390.        tprintf("f9   67    sf9   92    cf9  102    af9  112   ins    82\n");
  391.        tprintf("f10  68    sf10  93    cf10 103    af10 113   del    83\n");
  392.        tprintf("usage: fkey <key number> [<value> | \"string\"]\n");
  393.        return 0;
  394.     }
  395.  
  396.     c = atoi(argv[1]);
  397.     if (c == 0 || c > 255) {
  398.         tprintf("fkey number out of range.\n");
  399.         return 1;
  400.     }
  401.  
  402.     for (j = 0; (i = fkeys[j].fkey) != 0; j++)
  403.         if (i == c) 
  404.             break;
  405.  
  406.     if (i == 0)    {
  407.         tprintf("fkey number not found\n");
  408.         return 1;
  409.     }
  410.  
  411.     if (argc == 2) {
  412.         q = fkeys[j].fvalue;
  413.         r = str;
  414.         if (q == NULLCHAR)
  415.             tprintf("fkey %d has no assigned value.\n", c);
  416.         else {
  417.             
  418.             while (*q)
  419.                 if (*q < ' ') {                     /* This is ASCII dependent !!     */
  420.                     *r++ = '^';
  421.                     *r++ = *q++ + 0x40;
  422.                 } else
  423.                     *r++ = *q++;
  424.                     
  425.             *r = '\0';
  426.  
  427.             switch (fkeys[j].special) {
  428.                 case 1:
  429.                     special = "[command]";
  430.                     break;
  431.                 default:
  432.                     special = "";
  433.                 break;
  434.             }
  435.  
  436.             tprintf("fkey = %s%s\n", special, str);
  437.         }
  438.         return 0;
  439.     }
  440.  
  441.     if (argc == 3) {
  442.         if (fkeys[j].alloced)
  443.             fkeys[j].alloced = 0;
  444.         else
  445.             if (fkeys[j].fvalue != NULLCHAR)
  446.                 free(fkeys[j].fvalue);
  447.         fkeys[j].special = 0;
  448.  
  449.         r = str;
  450.         q = argv[2];
  451.         
  452.         if (strncmp(argv[2], "[command]", 9) == 0) {
  453.             q += 9;
  454.             fkeys[j].special = 1;
  455.         }
  456.  
  457.         while(*q)    {
  458.             if (*q == '^')    {                        /* ^ gives control char next         */
  459.                 q++;
  460.                 if (*q == '^') {
  461.                     *r++ = *q++;                     /* No, he wants a ^                     */
  462.                 } else {
  463.                     *r++ = *q++ & 0x1f;
  464.                 }
  465.             } else
  466.                 *r++ = *q++;
  467.         }
  468.  
  469.         *r = '\0';
  470.         fkeys[j].fvalue = strdup(str);
  471.     }
  472.     return 0;
  473. }
  474.  
  475.  
  476. /****************************************************************************
  477. *                                                                           *
  478. *    Virtual Interrupt handling functions                                     *
  479. *                                                                           *
  480. ****************************************************************************/
  481.  
  482. /*---------------------------------------------------------------------------
  483.     istate - return the current virtual interrupt sataus
  484. ---------------------------------------------------------------------------*/
  485.  
  486. int istate(void)
  487. {
  488.    return (int)Virtual_Interrupt_Enable;
  489. }
  490.  
  491.  
  492. /*---------------------------------------------------------------------------
  493.     dirps - disable Virtual Interrupts and return the previous status
  494. ---------------------------------------------------------------------------*/
  495.  
  496. int dirps(void)
  497. {
  498.    int prior = Virtual_Interrupt_Enable;
  499.  
  500.    if (Virtual_Interrupt_Enable) 
  501.       Virtual_Interrupt_Enable = 0;
  502.  
  503.    return prior;
  504. }
  505.  
  506.  
  507. /*---------------------------------------------------------------------------
  508.     restore - restore the Virtual Interrupt sataus
  509. ---------------------------------------------------------------------------*/
  510.     
  511. void restore(int foo)
  512. {
  513.    if (foo && !Virtual_Interrupt_Enable) {
  514.       Virtual_Interrupt_Enable = 1;
  515.    }
  516. }
  517.  
  518.  
  519. /*---------------------------------------------------------------------------
  520.     disable -
  521. ---------------------------------------------------------------------------*/
  522.     
  523. int disable()
  524. {
  525.     return 1;
  526. }
  527.  
  528.  
  529. /*--------------------------------------------------------------------------
  530.     doshell - function not currently used
  531. ---------------------------------------------------------------------------*/    
  532.  
  533. void doshell(int argc, char *argv[])
  534. {
  535. #if 0
  536. #ifdef SCREEN
  537.     /* make sure that we are on the right (main) screen */
  538.     dispscreen(0);
  539.     toggle = 0;
  540. #endif /* SCREEN */
  541.     if (argc < 2) {
  542.         args[0]="shell";
  543.         args[1]=NULL;
  544.         execstat = exec(shell,args);
  545.     } else
  546.         execstat = exec(argv[1],&argv[1]);
  547.  
  548.     if (execstat != 0)
  549.         printf("Pexec: errorcode: %ld\n",execstat);
  550.  
  551.     printf("\n");
  552.     (void)Cursconf(1,0);        /* cursor on */
  553.     (void)Cursconf(2,0);        /* cursor blink */
  554. #endif
  555. }
  556.  
  557.  
  558. /*---------------------------------------------------------------------------
  559.     memstat - Report on memory status
  560. ---------------------------------------------------------------------------*/
  561.  
  562. void    memstat()
  563. {
  564.  
  565. /*    long size;  */
  566.     void *size;
  567.  
  568.     size = Malloc(-1L);
  569.     printf("\nFree memory: %ld bytes.\n\n",size);
  570.  
  571.     printf("AUX:");
  572.     iosize(0);
  573. #if 0
  574.     printf("MIDI:");
  575.     iosize(2);
  576. #endif
  577. }
  578.  
  579.  
  580. /*---------------------------------------------------------------------------
  581.     iosize - report the I/O buffer size
  582. ---------------------------------------------------------------------------*/
  583.  
  584. void iosize(int i)
  585. {
  586.     struct iorec *rsbuffer;
  587.  
  588.     rsbuffer = (struct iorec*) Iorec(i);        /* get iorec */
  589.     printf("\tIorec:  %08lx\n", rsbuffer);
  590.     printf("\tBuffer: %08x\n", rsbuffer->ibuf);
  591.     printf("\tSize:   %d bytes\n", rsbuffer->ibufsiz);
  592. }
  593.  
  594.  
  595. /****************************************************************************
  596. *                                                                           *
  597. *    Display handling functions                                               *
  598. *                                                                           *
  599. ****************************************************************************/
  600.  
  601. /*---------------------------------------------------------------------------
  602.     display - the main display task, it sucks output from the "active" session
  603.                  and displays it.
  604. ---------------------------------------------------------------------------*/
  605.  
  606. void display(int i, void *v1, void *v2)
  607. {
  608.     int c;
  609.     struct session *sp;
  610.  
  611.     for( ; ; ) {
  612.         sp = Current;
  613.  
  614.         if (sp->morewait) {
  615.             pwait(&sp->row);
  616.             if(sp != Current || sp->row <= 0){
  617.                 /* Current changed value, or the user
  618.                  * hasn't really hit a key
  619.                  */
  620.                 continue;
  621.             }
  622.             /* Erase the '--More--' prompt */
  623.              cputs("\r        \r");
  624.             sp->morewait = 0;
  625.         }
  626.  
  627.         if ((c = recvchar(sp->output)) == -1){
  628.             /* the alert() in swapscreen will cause this to
  629.              * return -1 when current changes
  630.              */
  631.             pwait(NULL);
  632.             continue;
  633.         }
  634.  
  635.         if (sp->record != NULLFILE) {                /* log character if required */
  636.             if (c != '\r')
  637.                 fputc(c, sp->record);
  638.         }
  639.         
  640. /*        cputc((char)c); */
  641.             Bconout(2, (char)c);                        /* write character to console    */
  642.  
  643.         if (c == '\n') {                                /* if newline found                */
  644. /*            cputc('\r'); */
  645.             Bconout(2, '\r');                            /* write CR                            */
  646.             
  647.             if(sp->flowmode && --sp->row <= 0) {
  648.                 cputs("--More--");
  649.                 sp->morewait = 1;
  650.             }
  651.         }
  652.     }
  653. }
  654.  
  655. #ifdef SCREEN
  656.  
  657. /*---------------------------------------------------------------------------
  658.  dispscreen selects the screen to be displayed by the video hardware.
  659.  * this routine is called from within kbread()
  660.  * flag:  =0: display normal screen
  661.  *       <>0: display trace screen
  662. ---------------------------------------------------------------------------*/ 
  663.  
  664. void dispscreen(int flag)
  665. {
  666.     if (flag == 0) {
  667.         (void) Setscreen(old_logscr, old_physcr, -1);
  668.         (void) Vsync();
  669.         printf("\033e");    /* turn on cursor */
  670.     } else {
  671.         (void) Setscreen(new_logscr, new_physcr, -1);
  672.         (void) Vsync();
  673.         printf("\033f");    /* turn off cursor */
  674.     }
  675. }
  676.  
  677.  
  678. /*---------------------------------------------------------------------------
  679.     outscreen - outscreen selects one of two screens where display output
  680.                (printf's) should go to.  outscreen is called from trace.c
  681.                before/after trace output is done
  682. ---------------------------------------------------------------------------*/
  683.  
  684. void outscreen(int flag)
  685. {
  686.     if (flag == 0) {
  687.         (void) Setscreen(old_logscr, old_physcr, -1);
  688.         (void) Vsync();
  689.         printf("\033k");    /* restore cursor pos on main screen */
  690.     } else {
  691.         (void) Setscreen(new_logscr, new_physcr, -1);
  692.         (void) Vsync();
  693.         printf("\033j");    /* save cursor pos on main screen */
  694.         printf("\033Y%c%c",rows+31,32);
  695.     }
  696. }
  697. #endif
  698.  
  699.  
  700. /*---------------------------------------------------------------------------
  701.     set_stdout - set console output to binary or ascii mode (raw or cooked...)
  702.                      mode == 1 means raw, anything else means cooked.
  703. ---------------------------------------------------------------------------*/
  704.  
  705. void set_stdout(int mode)
  706. {
  707.     fmode(stdout, mode);
  708.     fflush(stdout);
  709.     setbuf(stdout, NULL);  /* disable all buffering */
  710. }
  711.  
  712. #if 0
  713. long ptol(void *ptr)
  714. {
  715.    return (long) ptr;
  716. }
  717.  
  718. void *ltop(long l)
  719. {
  720.    return (void *)l;
  721. }
  722. #endif
  723.  
  724. /*---------------------------------------------------------------------------
  725.     domem - memory reporting function
  726. ---------------------------------------------------------------------------*/
  727.  
  728. int domem(int argc,
  729.           void *argv[],
  730.           void *p )
  731. {
  732.     tprintf("Coreleft = %x \n", coreleft());
  733.  
  734.     return 0;
  735. }
  736.  
  737.  
  738. /*---------------------------------------------------------------------------
  739.     clear - clear the screen and home the cursor
  740. ---------------------------------------------------------------------------*/
  741.  
  742. int doclear(int argc,
  743.                 void *argv[],
  744.                 void *p )
  745. {
  746.     tprintf("\033E");
  747.     tflush();
  748. }
  749.  
  750.           
  751. /****************************************************************************
  752. *                                                                           *
  753. *    Dummy and mapping functions                                              *
  754. *                                                                           *
  755. ****************************************************************************/
  756.  
  757. #if 0
  758.  
  759. /*---------------------------------------------------------------------------
  760.     rflush - Flush the raw terminal output
  761. ---------------------------------------------------------------------------*/
  762.  
  763. void rflush()
  764. {
  765.     fflush(stdout);
  766. }
  767. #endif
  768.  
  769. /*---------------------------------------------------------------------------
  770.     mallocw - all malloc calls run through here
  771. ---------------------------------------------------------------------------*/
  772.     
  773. void *mallocw(unsigned n)
  774. {
  775.     return malloc((size_t)n);
  776. }
  777.  
  778.  
  779. /*---------------------------------------------------------------------------
  780.     callocw - all calloc calls run through here
  781. ---------------------------------------------------------------------------*/
  782.     
  783. void *callocw(unsigned n, unsigned size)
  784. {
  785.     return calloc((size_t)n, (size_t)size);
  786. }
  787.  
  788.  
  789. /*---------------------------------------------------------------------------
  790.     availmem - report on available memory
  791. ---------------------------------------------------------------------------*/
  792.     
  793. unsigned long availmem(void)
  794. {
  795.     return 16535;
  796. }
  797.  
  798. /****************************************************************************
  799. *                                                                           *
  800. *   T H E   E N D                                                           *
  801. *                                                                           *
  802. ****************************************************************************/
  803.